// sd_liferuning/pages/module-mananger/authentication/index.js
var api = require("../../../../api.js"),
  QQMapWX = require("../../../../qqmap-wx.js"),
  app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShow: false,
    moduleArr: [
      {
        joint_id:1,
        j_name: 'AAA'
      },
      {
        joint_id: 2,
        j_name: 'BBB'
      },
      {
        joint_id: 3,
        j_name: 'CCC'
      }
    ]
  },
  formSubmit: function(e){
    let _this = this;
    let _val = e.detail.value;
    // if (_val.wechatID == ''){
    //   wx.showToast({
    //     title: '小程序ID不得为空',
    //     icon: 'none'
    //   })
    //   return false;
    // }

    // if (_val.appID == '') {
    //   wx.showToast({
    //     title: 'AppID不得为空',
    //     icon: 'none'
    //   })
    //   return false;
    // }

    // if (_val.appName == '') {
    //   wx.showToast({
    //     title: '小程序名称不得为空',
    //     icon: 'none'
    //   })
    //   return false;
    // }
    _this.sendRequest(_val);
  },
  onLoad:function(){
    var that = this
    that.setData({
      icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
    });
  },
  onShow:function(){
    var that = this;
    app.request({
      url: api.order.YesJoint,
      success: function (e) {
        that.setData({
          moduleArr: e.mess,
          moduleIndex: 0
        })
      }
    })
  },
  sendRequest: function(formData){
    let _wechatID = formData.wechatID;
    let _appID = formData.appID;
    let _appName = formData.appName;
    let _joint_id = formData.j_name;
    let yes_no = formData.userType;
    let appName = formData.shopName;
    if (appName==undefined){
      appName = '';
    }
    // TODO 执行请求
    console.log("TODO 执行请求");
    app.request({
      url: api.order.sumbit_ShenHe,
      method:'post',
      data: {
        uid: wx.getStorageSync('uid'),
        bid: wx.getStorageSync('bid'),
        name: _appName,
        appid: _appID,
        hjmall_id: _wechatID,
        is_zguanli: yes_no,
        type: _joint_id,
        shop_name:appName
      },
      success: function (e) {
        console.log(e)
        if(e.code==1){
          wx.showToast({
            title: '成功',
            icon: 'succes',
            duration: 1000,
            mask: true
          })
          wx.navigateTo({
            url:'/sd_liferuning/pages/constmer/user/index',  
          })
        }else{
          wx.showToast({
            title: '失败',
            duration: 1000,
            mask: true
          })
          wx.navigateTo({
            url: '/sd_liferuning/pages/constmer/user/index',
          })
        }
      }
    })
  },
  userTypeBindChange: function(e){
    let _val = e.detail.value;
    this.setData({
      isShow: _val == 0 ? true : false
    })
  },
  bindModulePickerChange: function(e){
    let _index = e.detail.value;
    this.setData({
      moduleIndex: _index
    })
  }
})